import cv2
import numpy as np

# 读取图像
img = cv2.imread('photo4.jpg')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# 进行 Harris 角点检测
gray = np.float32(gray)
dst = cv2.cornerHarris(gray, 2, 3, 0.04)

# 膨胀角点以使其更明显
dst = cv2.dilate(dst, None)

# 标记角点
img[dst > 0.01 * dst.max()] = [0, 0, 255]

# 显示结果
cv2.imshow('Harris Corners', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
